package com.zb.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.zb.entity.Houseinfo;
import com.zb.service.HouseinfoService;
import com.zb.utils.ConstantUtil;
import com.zb.utils.PageUtil;

@Controller
@RequestMapping("houseinfo")
public class HouseinfoController {
	@Autowired
	private HouseinfoService houseinfoService;

	@RequestMapping("list")
	@ResponseBody
	public String findByConditions(Integer startPageNo) {
		PageUtil<Houseinfo> result = houseinfoService.findByConditions(
				startPageNo, ConstantUtil.PAGE_SIZE);
		return JSONObject.toJSONString(result);
	}

	@RequestMapping("add")
	public String add(@ModelAttribute("houseinfo") Houseinfo houseinfo) {
		// 设置发布日期
		houseinfo.setPublishDate(new Date());
		Integer count = houseinfoService.add(houseinfo);
		if (count > 0) {
			return "redirect:/houseinfolist.jsp";
		} else {
			return "forward:/houseinfoadd.jsp";
		}
	}
}
